//模块主窗口
var NOSTOPUSER =  NOSTOPUSER||{};
NoStopUserAnalysePanel = Ext
		.extend(
				Ext.Panel,
				{
					closable : true,
					autoScroll : true,
					width : '100%',
					height : 700,
					initComponent : function() {

						this.tbar = this.buildBbar();
						var dataStore = new Ext.data.JsonStore({
							url:"chart_getTrendsChartReport.action?monitorType=2", 
							root: 'root',
					        idProperty: 'id',
					        fields: [
					           'CYCLE_ID','ALLCOUNT'
					        ]
						});
						var gdp = new NoStopUserAnalyseListPanel();
						var chart = new NOSTOPUSER.UserNumberChar({'monitorTypes':this.monitorType,'dataStore':dataStore});
						this.items = [new QueryStatnostopuserAForm({
							thisGrid:gdp
							,chartPanel:chart
							}),chart,gdp] ;
						this.formPanel = new Ext.Window({
							layout : "border",
							title : "按条件查询停机又产生话单用户信息",
							closeAction : 'hide',
							resizable : false,
							modal : true,
							width : 550,
							height : 300,
							items : [ new StatNoStopUserForm({
								thisGrid : gdp
							}) ]
						});
						NoStopUserAnalysePanel.superclass.initComponent
								.call(this);
					},
					statOweFeeUser : function(btn) {
						var cycleId = btn.ownerCt.ownerCt.cycleId.getValue();
						var chartURL = null;
						if (btn.chartType == "Z") {
							chartURL = "ext-3.4.0/charts/FCF_MSColumn3D.swf";
						} else if (btn.chartType == "Y") {
							chartURL = 'ext-3.4.0/charts/MSLine.swf';
						}
						var mk = new Ext.LoadMask(Ext.getBody(), {
							msg : '正在加载数据，请稍候！',
							removeMask : true
						// 完成后移除
						});
						mk.show();
						Ext.Ajax
								.request({
									url : "highFeeUser_getChartReport.action?modleType=1&chartType="
											+ btn.chartType
											+ "&cycleId="
											+ cycleId,
									success : function(response) {
										var Result = Ext
												.decode(response.responseText);
										var strXml = Result.info;
										var fusionPanel = new Ext.ux.Chart.Fusion.Panel(
												{
													collapsible : false,
													chartCfg : {
														id : 'chart1',
														params : {
															flashVars : {
																debugMode : 0,
																lang : 'EN'
															}
														}
													},
													dataXML : strXml,
													id : 'chartpanel',
													chartURL : chartURL,
													width : 700,
													height : 400
												});
										var Fwin = new Ext.Window({
											name : 'Fwin',
											width : '1280',
											height : '620',
											layout : 'fit',
											closeAction : 'close',
											title : '统计图表显示',
											buttonAlign : 'center',
											modal : true,
											items : [ fusionPanel ],
											buttons : [ {
												text : '退出',
												iconCls : 'icon_exit',
												handler : function() {
													Fwin.close();
												}
											} ]
										});
										mk.hide();
										Fwin.show();
									},
									failure : function(response) {
										mk.hide();
										Ext.Msg.alert("提示", "服务器请求错误,请稍后再试！");
									}
								});
					},

					statHighFeeUserAll : function(btn) {
						var cycleId = btn.ownerCt.ownerCt.cycleId.getValue();
						var mk = new Ext.LoadMask(Ext.getBody(), {
							msg : '正在加载数据，请稍候！',
							removeMask : true
						// 完成后移除
						});
						mk.show();
						Ext.Ajax
								.request({
									url : "highFeeUser_getChartAnalyse.action?modleType=1&cycleId="
											+ cycleId,
									success : function(response) {
										var Result = Ext
												.decode(response.responseText);
										var strXml = Result.info;
										var fusionPanel = new Ext.ux.Chart.Fusion.Panel(
												{
													collapsible : false,
													chartCfg : {
														id : 'chart1',
														params : {
															flashVars : {
																debugMode : 0,
																lang : 'EN'
															}
														}
													},
													dataXML : strXml,
													id : 'chartpanel',
													chartURL : 'ext-3.4.0/charts/MSStackedColumn2DLineDY.swf',
													width : 700,
													height : 400
												});
										var Fwin = new Ext.Window({
											name : 'Fwin',
											width : '1280',
											height : '620',
											layout : 'fit',
											closeAction : 'close',
											title : '综合统计图表分析',
											buttonAlign : 'center',
											modal : true,
											items : [ fusionPanel ],
											buttons : [ {
												text : '退出',
												iconCls : 'icon_exit',
												handler : function() {
													Fwin.close();
												}
											} ]
										});
										mk.hide();
										Fwin.show();
									},
									failure : function(response) {
										mk.hide();
										Ext.Msg.alert("提示", "服务器请求错误,请稍后再试！");
									}
								});
					},
					statHighFeeUserMonth : function(btn) {
						var cycleId = btn.ownerCt.ownerCt.cycleId.getValue();
						var mk = new Ext.LoadMask(Ext.getBody(), {
							msg : '正在加载数据，请稍候！',
							removeMask : true
						// 完成后移除
						});
						mk.show();
						Ext.Ajax
								.request({
									// ext.windows.url
									url : "highFeeUser_getChartMonth.action?modleType=1&cycleId="
											+ cycleId,
									success : function(response) {
										var Result = Ext
												.decode(response.responseText);
										var strXml = Result.info;
										var fusionPanel = new Ext.ux.Chart.Fusion.Panel(
												{
													collapsible : false,
													chartCfg : {
														id : 'chartMonth',
														params : {
															flashVars : {
																debugMode : 0,
																lang : 'EN'
															}
														}
													},
													dataXML : strXml,
													id : 'chartMonthPanel',
													chartURL : 'ext-3.4.0/charts/ScrollCombi2D.swf',
													width : 700,
													height : 400
												});
										var Fwin = new Ext.Window({
											name : 'Fwin',
											width : '1280',
											height : '620',
											layout : 'fit',
											closeAction : 'close',
											title : '月度分析统计图表',
											buttonAlign : 'center',
											modal : true,
											items : [ fusionPanel ],
											buttons : [ {
												text : '退出',
												iconCls : 'icon_exit',
												handler : function() {
													Fwin.close();
												}
											} ]
										});
										mk.hide();
										Fwin.show();
									},
									failure : function(response) {
										mk.hide();
										Ext.Msg.alert("提示", "服务器请求错误,请稍后再试！");
									}
								});
					},
					statOweFeeUserByCond : function(btn) {
						var tform = btn.ownerCt.ownerCt.formPanel;
						tform.show();
					},
					exportData : function(btn) {
						var gp = btn.ownerCt.ownerCt.items.get(2);
						var st = gp.getStore();
						Ext.MessageBox
								.confirm(
										"确认",
										"确定导出?",
										function(btn) {
											if (btn == "yes") {
													window.location.href ="nostopuser_exportNoStopUserAnalyseToExcel.action";
											}
										});

					},
					buildBbar : function() {
						return [ 
				{
   				text : "显示查询",
   				iconCls: 'ico-dot-search-open',
   				handler:function(btn){
   					var m = btn.ownerCt.ownerCt;
   					var g = m.items.get(1);
   					var a = m.items.get(0);
   					a.setHeight(100);
   					a.searchBtn = btn;
   					if(a.collapsed) {
   						var h1 = m.getHeight()-m.tbar.dom.clientHeight-a.getHeight();
   						a.expand(true);
   						g.setHeight(h1-100);
   						btn.setText("隐藏查询");
   						btn.setIconClass("ico-dot-search-hidden");
   					} else {
   						a.collapse(true);
   						g.setHeight(m.getHeight()-m.tbar.dom.clientHeight-1);
   						btn.setText("显示查询");
   						btn.setIconClass("ico-dot-search-open");
   					}
				}
			},'-',{
					text : "数据导出",
					handler : this.exportData,
					iconCls : 'ico-dot-report'
	   			},'-',{
	   				text : "隐藏用户数量趋势图",
	   				handler :this.statHighFeeUser,
	   				handler:function(btn){
	   					var m = btn.ownerCt.ownerCt;
	   					var g = m.items.get(1);
	   					if(g.collapsed) {
	   						g.expand();
	   						btn.setText("显示用户数量趋势图");
	   						btn.setIconClass("ico-dot-chart-del");
	   					} else {
	   						g.collapse();
	   						btn.setText("隐藏用户数量趋势图");
	   						btn.setIconClass("ico-dot-chart-add");
	   					}
	   				},
	   				iconCls: 'ico-dot-chart-add'
	   			},'->',{
                    	text:'使用说明'          
                      ,iconCls:'ico-dot-book-question'
                    	,handler:function(){
                    		SM.Explanation.showExplanation(27);
                    	}
                    }
];
					}
				});

// 按条件统计高额用户
StatNoStopUserForm = Ext.extend(Ext.form.FormPanel, {
	text : "表单",
	layout : "form",
	region : "center",
	labelAlign : "right",
	width : 550,
	height : 400,
	frame : true,
	initComponent : function() {
		var cityNameSelect = new Ext.data.JsonStore({
			url : "Settle_getCityCode.action",//第一个comboBox的json数据的URL地址
			root : "root",
			fields : [ "paramValue", "displayValue" ]
		});
		this.items = [
				{
					fieldLabel : '所属地市',
					name : 'eparchyCode',
					xtype : 'combo',
					editable : false,
					mode : 'remote',
					triggerAction : 'all',
					valueField : "paramValue",
					displayField : "displayValue",
					store : areaCodeSelect,
					emptyText : "请选择",
					anchor : "90%",
					listeners : {
						"select" : function(combo) {
							combo.ownerCt.getForm().findField("cityCode")
									.reset();
							cityNameSelect.baseParams = {
								'areaCode' : combo.getValue()
							};
							cityNameSelect.load();
						}
					}
				},
				{
					fieldLabel : '所属区县',
					name : 'cityCode',
					xtype : 'combo',
					editable : false,
					mode : 'remote',
					triggerAction : 'all',
					valueField : "paramValue",
					displayField : "displayValue",
					store : cityNameSelect,// cityCodeSelect
					emptyText : "请选择",
					anchor : "90%"
				},
				{
					fieldLabel : '账&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;期',
					name : 'cycleId',
					xtype : 'combo',
					editable : false,
					mode : 'local',
					triggerAction : 'all',
					emptyText : "请选择",
					store : getCyids(),
					anchor : "90%"
				},
				{
					fieldLabel : '稽核类型',
					name : 'bizType',
					xtype : 'combo',
					editable : false,
					mode : 'local',
					triggerAction : 'all',
					store : [ [ '1', '该停未停-固网' ], [ '2', '该停未停-移网' ],
							[ '3', '地市审核-单停未停' ], [ '4', '地市审核-全停未停' ] ],
					anchor : "90%",
					emptyText : "请选择"
				} ];
		StatNoStopUserForm.superclass.initComponent.call(this);
	},
	buttonAlign : 'center',
	minButtonWidth : 60,
	buttons : [ {
		text : "确定",
		handler : function(btn) {
			var thisForm = btn.ownerCt.ownerCt.getForm();

			var eparchyCode = thisForm.findField('eparchyCode').getValue();
			var cityCode = thisForm.findField('cityCode').getValue();
			var cycleId = thisForm.findField('cycleId').getValue();
			var bizType = thisForm.findField('bizType').getValue();

			var store = btn.ownerCt.ownerCt.thisGrid.getStore();

			btn.ownerCt.ownerCt.thisGrid.recordStart = 1;
			store.baseParams = {
				'tsOfNostopuser.eparchyCode' : eparchyCode,
				'tsOfNostopuser.cityCode' : cityCode,
				'tsOfNostopuser.cycleId' : cycleId,
				'tsOfNostopuser.bizType' : bizType
			};

			store.load({
				params : {
					start : 0,
					limit : 21
				}
			});

			this.ownerCt.ownerCt.ownerCt.hide();// 隐藏弹出页面
		}
	}, {
		text : '重置',
		handler : function() {
			this.ownerCt.ownerCt.form.reset();
		}
	}, {
		text : '取消',
		handler : function() {
			this.ownerCt.ownerCt.ownerCt.hide();
		}
	} ]
});

// 高额用户统计信息列表
NoStopUserAnalyseListPanel = Ext.extend(Ext.grid.EditorGridPanel, {
	title : '信息列表',
	id : 'owefee-user-list-panel',
	header: false,
	frame : true,
	enableDragDrop : false,
	viewConfig : {
		forceFit : true
	},
	loadMask:{msg:'加载中...'},
	columnLines:true,
	headerAlign:"center",
	height:600,
	initComponent : function() {
		var thisGrid = this;
		this.recordStart = 1;

		var rn = new Ext.grid.RowNumberer({
			header : "序号",
			width : 35,
			headerAlign :"center" //列头对齐方式
				,align :"left" //列值对齐方式
					,allowHeaderWrap:true //
					,allowWrap:false
					,cellTip:true, //列提示,
			renderer : function(value, metadata, record, rowIndex) {
				return thisGrid.recordStart + rowIndex;
			}
		});

		this.columns = this.buildColUI(rn);
		var dataStore = new Ext.data.JsonStore({
			url : 'nostopuser_getNoStopUserAnalyseByCond.action',
			root : 'root',
			totalProperty : 'totalProperty',
			idProperty : 'id',
			fields : [ 'EPARCHY_CODE', 'CYCLE_ID', 'BIZ_TYPE', 'COUNT' ]
		});
		dataStore.baseParams = {
			'tsOfNostopuser' : null
		};
		this.store = dataStore;
		// this.sm = highFeeUserCm;;
		this.bbar = new Ext.PagingToolbar({
			pageSize : 200,
			store : dataStore,
			displayInfo : true,
			displayMsg : '第 {0} - {1} 条  共 {2} 条',
			emptyMsg : "没有记录",
			listeners : {
				beforechange : function(pt, obj) {
					thisGrid.recordStart = obj.start + 1;

				}
			}
		});
		dataStore.load({
			params : {
				start : 0,
				limit : 200
			}
		});
		NoStopUserAnalyseListPanel.superclass.initComponent.call(this);
	},
	buildColUI : function(rn) {
		return [ rn, {
			header : '所属地市',
			sortable : true,
			dataIndex : "EPARCHY_CODE",
			headerAlign :"center" //列头对齐方式
				,align :"left" //列值对齐方式
					,allowHeaderWrap:true //
					,allowWrap:false
					,cellTip:true //列提示
		}, {
			header : '账期',
			sortable : true,
			dataIndex : "CYCLE_ID",
			headerAlign :"center" //列头对齐方式
				,align :"left" //列值对齐方式
					,allowHeaderWrap:true //
					,allowWrap:false
					,cellTip:true //列提示
		}, {
			header : '稽核类型',
			sortable : true,
			dataIndex : "BIZ_TYPE",
			headerAlign :"center" //列头对齐方式
				,align :"left" //列值对齐方式
					,allowHeaderWrap:true //
					,allowWrap:false
					,cellTip:true //列提示
		}, {
			header : '用户数量(户)',
			sortable : true,
			dataIndex : "COUNT",
			headerAlign :"center" //列头对齐方式
				,align :"left" //列值对齐方式
					,allowHeaderWrap:true //
					,allowWrap:false
					,cellTip:true //列提示
		} ];
	}
});
QueryStatnostopuserAForm = Ext.extend(Ext.form.FormPanel,{
	region : "center",
	labelAlign:"right",
	width:"100%",
	collapsible:true,
	collapsed:false,
	header:false,
	height:1,
	frame:true,
	layout:'table',
	layoutConfig:{
	tableAttrs: {
		align:'left'
	 },
	columns: 4
	},
	initComponent: function(){
		var cityNameSelect = new Ext.data.JsonStore({
		    url: "highFee_getCityCode.action?type=1",//第一个comboBox的json数据的URL地址
		    root: "root",
		    fields: ["paramValue", "displayValue"]
		});
	this.items=[{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '所属地市',
							name : 'eparchyCode',
							xtype : 'combo',
							editable : false,
							mode : 'remote',
							triggerAction : 'all',
							valueField: "paramValue",
 							displayField: "displayValue",
							store : areaCodeSelect,
							emptyText:"请选择",
							width:100,
							listeners : {
	 						"select": function(combo){
								combo.ownerCt.ownerCt.getForm().findField("cityCode").reset();
								cityNameSelect.baseParams={'areaCode':combo.getValue()};
								cityNameSelect.load();
						}}}]},{
							layout : "form",
							xtype:'panel',
							colspan:1,
							items:[{
							fieldLabel : '所属区县',
							name : 'cityCode',
							xtype : 'combo',
							editable : false,
							mode : 'remote',
							triggerAction : 'all',
							valueField : "paramValue",
							displayField : "displayValue",
							store : cityNameSelect,// cityCodeSelect
							emptyText : "请选择",
							width:100
					    }]},{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{
					fieldLabel : '账&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;期',
					name : 'cycleId',
					xtype : 'combo',
					editable : false,
					mode : 'local',
					triggerAction : 'all',
					emptyText : "请选择",
					store : getCyids(),
					width:100
		    	}]},{ 
			    	layout : "form",
			    	xtype:'panel',
			    	colspan:1,
			    	items:[{
						fieldLabel : '稽核类型',
						name : 'bizType',
						xtype : 'combo',
						editable : false,
						mode : 'local',
						triggerAction : 'all',
						store : [ [ '1', '该停未停-固网' ], [ '2', '该停未停-移网' ],
									[ '3', '地市审核-单停未停' ], [ '4', '地市审核-全停未停' ] ],
								width:150,
						emptyText : "请选择"
					}]}];
	  QueryStatnostopuserAForm.superclass.initComponent.call(this);
	},
	buttonAlign :'center',
	minButtonWidth:60,
	buttons:[{
		text:"确定",
		handler : function(btn){
			var thisForm = btn.ownerCt.ownerCt
			.getForm();

	var eparchyCode = thisForm.findField(
			'eparchyCode').getValue();
	var cityCode = thisForm.findField(
			'cityCode').getValue();
	 var cycleId =thisForm.findField('cycleId').getValue();
	var bizType = thisForm.findField('bizType')
			.getValue();



	var store = btn.ownerCt.ownerCt.thisGrid
			.getStore();

	btn.ownerCt.ownerCt.thisGrid.recordStart = 1;
	store.baseParams = {
		'tsOfNostopuser.eparchyCode' : eparchyCode,
		'tsOfNostopuser.cityCode' : cityCode,
		'tsOfNostopuser.cycleId' : cycleId,
		'tsOfNostopuser.bizType' : bizType
	};


          store.load({params:{start:0, limit:200}});
		    
		   //this.ownerCt.ownerCt.ownerCt.hide();//隐藏弹出页面
		}
	}, {
		text : '重置',
		handler : function() {this.ownerCt.ownerCt.form.reset();}
	}, {
		text : '关闭',
		handler : function() {
		this.ownerCt.ownerCt.collapse(true);
			var m = this.ownerCt.ownerCt.ownerCt;
 					var g = m.items.get(1);
 					var a = m.items.get(0);
			g.setHeight(m.getHeight()-m.tbar.dom.clientHeight-1);
 			this.ownerCt.ownerCt.searchBtn.setText("显示查询");
   			this.ownerCt.ownerCt.searchBtn.setIconClass("ico-dot-search-open");
		}
	}]
});
NOSTOPUSER.UserNumberChar = Ext.extend(Ext.Panel,{
    width: "100%",
    collapsible:true,
	collapsed:false,
	title:'每日用户量趋势图',
    height: 350,
    initComponent: function(){
    	var thisPanel = this;
        var dataStore = this.dataStore;
		//dataStore.load();
		this.store = dataStore;
        this.items = [{
            xtype: 'linechart',
            store: dataStore,
            plugins:[new Ext.ux.plugin.VisibilityMode()],
            yAxis: new Ext.chart.NumericAxis({  
	            title: '异常用户数(户)'
	        })
	        ,tipRenderer : function(chart, record, index, series){
	        	if(series.yField=="ALLCOUNT") {
	        		return series.displayName+"\n"+record.data['CYCLE_ID']+"\n"+Ext.util.Format.number(series.data[index]['ALLCOUNT'])+"户";
	        	}
	        	/*
	        	if(series.yField=="yj") {
	        		return series.displayName+"\n"+record.data['statDay']+"\n"+Ext.util.Format.number(series.data[index]['yj'])+"户";
	        	}else if(series.yField=="tj") {
	        		return series.displayName+"\n"+record.data['statDay']+"\n"+Ext.util.Format.number(series.data[index]['tj'])+"户";
	        	}else if(series.yField=="gj") {
	        		return series.displayName+"\n"+record.data['statDay']+"\n"+Ext.util.Format.number(series.data[index]['gj'])+"户";
	        	}else if(series.yField=="userCount") {
	        		return series.displayName+"\n"+record.data['statDay']+"\n"+Ext.util.Format.number(series.data[index]['userCount'])+"户";
	        	}*/
	        }
	        ,extraStyle: {
	        	xAxis: {  
	                labelRotation: -30//x轴标题旋转度数
	                ,majorGridLines: {size: 1, color: 0xdfe8f6}
	                ,majorTicks: {color: 0x69aBc8, length: 4},
           			 minorTicks: {color: 0x69aBc8, length: 2}
	            },  
	            yAxis: {  
	                labelRotation: 0//y轴标题旋转度数  
	            	,titleRotation:-90
	            	,majorGridLines: {size: 1, color: 0xeeeeee}
//	            	,majorTicks: {color: 0x69aBc8, length: 4},
//           			 minorTicks: {color: 0x69aBc8, length: 2}
	            } ,
	            legend:{
	            	display:'top'
	            }
	            ,visibility:false
	        }  
            ,series: [/*{
                displayName: '预警用户',
                type: 'line',
            	yField: 'yj',
            	xField: 'statDay',
                style: {
                	size:8
                }
            },{
                 type: 'line',
            	yField: 'gj',
            	xField: 'statDay',
                displayName: '告警用户',
                style: {
                	color:0xffff00,
                	size:8
                }
            },{
                 type: 'line',
            	yField: 'tj',
            	xField: 'statDay',
                displayName: '严重用户',
                style: {
                	color:0xFF0080,
                	size:8
                }
            },*/{
                type: 'line',
            	yField: 'ALLCOUNT',
            	xField: 'CYCLE_ID',
                displayName: '总用户量',
                style: {
                	color:0x800080,
                	size:8
                }
            }
//            ,{
//                type: 'line',
//            	yField: 'feeCount',
//            	xField: 'statDay',
//                displayName: '总费用'
//            }
            ]
        }];
        NOSTOPUSER.UserNumberChar.superclass.initComponent.call(this);
    },listeners : {
		'afterrender':function(com) {
			com.store.load();
			}
}
});